{extend name="adminblue/base" /}
{block name="resources"/}
<style>
.modal-infp-style{width:90%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align:left;"><button class="btn-common btn-small" onclick="location.href='{:__URL('ADMIN_MAIN/promotion/combopackagepromotionEdit')}';" style="margin:0 5px 0 0 !important;">添加组合套餐</button></th>
		<th width="10%">
			<input type="text" id='search_text' placeholder="请输入組合套餐名称" class="input-common" />
			<input type="button" onclick="searchData()" value="搜索" class="btn-common" />
		</th>
	</tr>
</table>
<table class="table-class">
	<colgroup>
	<col style="width: 2%;">
	<col style="width: 44%;">
	<col style="width: 10%;">
	<col style="width: 8%;">
	<col style="width: 20%;">
	<col style="width: 16%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><i class="checkbox-common"><input type="checkbox" onclick="CheckAll(this)"></i></th>
			<th align="left">组合套餐名称</th>
			
			<th align="right">组合套餐价格</th>
			<th>状态</th>
			<th>创建时间</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/promotion/comboPackagePromotionList')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["id"]+'" ></i></td>';
					html += '<td style="text-align:left;">'+data["data"][i]['combo_package_name']+'</td>';
					
					html += '<td style="text-align:right;">'+data["data"][i]['combo_package_price']+'</td>';
					if(data["data"][i]['is_shelves'] == 0){
						html += '<td>已下架</td>';
					}else if(data["data"][i]['is_shelves'] == 1){
						html += '<td>已上架</td>';
					}
					html += '<td>'+timeStampTurnTime(data["data"][i]['create_time'])+'</td>';
					html += '<td><a href="'+__URL(ADMINMAIN+"/promotion/comboPackagePromotionEdit?id="+data["data"][i]["id"])+'">编辑</a><a href="javascript:;" onclick="delete_combo_package('+data["data"][i]["id"]+');">删除</a></td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	if(checked) $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().removeClass("selected");
}

function searchData(){
	LoadingInfo(1);
}

//删除组合套餐
function delete_combo_package(ids){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
			$.ajax({
				type : "post",
				url : "{:__URL('ADMIN_MAIN/promotion/deleteComboPackage')}",
				data : {"ids" : ids.toString()},
				success : function(data) {
					if(data["code"] > 0 ){
						LoadingInfo(1);
						showMessage('success', data["message"],window.location.reload());
					}
				}
			})
			$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"确定要删除吗？",
	});
}

/**
* 批量删除
*/
function batchDelete(){
	var order_ids= new Array();
	$(".table-class tbody input[type = 'checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			order_ids.push($(this).val());
		}
	});
	if(order_ids.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delete_order(order_ids);
}
</script>
{/block}